home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / WPrefs.app / WindowHandling.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-17  |  13.2 KB  |  457 lines

  1. /* WindowHandling.c- options for handling windows
  2.  * 
  3.  *  WPrefs - Window Maker Preferences Program
  4.  * 
  5.  *  Copyright (c) 1998 Alfredo K. Kojima
  6.  * 
  7.  *  This program is free software; you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation; either version 2 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  This program is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with this program; if not, write to the Free Software
  19.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
  20.  *  USA.
  21.  */
  22.  
  23.  
  24. #include "WPrefs.h"
  25.  
  26. typedef struct _Panel {
  27.     WMFrame *frame;
  28.  
  29.     char *sectionName;
  30.  
  31.     char *description;
  32.  
  33.     CallbackRec callbacks;
  34.     
  35.     WMWindow *win;
  36.     
  37.     WMFrame *placF;
  38.     WMPopUpButton *placP;
  39.     WMLabel *porigL;
  40.     WMLabel *porigvL;
  41.     WMFrame *porigF;
  42.     WMLabel *porigW;
  43.     
  44.     WMSlider *vsli;
  45.     WMSlider *hsli;
  46.  
  47.     WMFrame *resF;
  48.     WMSlider *resS;
  49.     WMLabel *resL;
  50.     WMButton *resaB;
  51.     WMButton *resrB;
  52.  
  53.     WMFrame *maxiF;
  54.     WMButton *miconB;
  55.     WMButton *mdockB;
  56.     
  57.     WMFrame *opaqF;
  58.     WMButton *opaqB;
  59.  
  60.     WMFrame *tranF;
  61.     WMButton *tranB;
  62. } _Panel;
  63.  
  64.  
  65. #define ICON_FILE "whandling"
  66.  
  67. #define OPAQUE_MOVE_PIXMAP "opaque"
  68.  
  69. #define NON_OPAQUE_MOVE_PIXMAP "nonopaque"
  70.  
  71.  
  72. #define THUMB_SIZE    16
  73.  
  74.  
  75. static char *placements[] = {
  76.     "auto",
  77.     "random",
  78.     "manual",
  79.     "cascade",
  80.         "smart"
  81. };
  82.  
  83.  
  84. static void
  85. sliderCallback(WMWidget *w, void *data)
  86. {
  87.     _Panel *panel = (_Panel*)data;
  88.     int x, y, rx, ry;
  89.     char buffer[64];
  90.     int swidth = WMGetSliderMaxValue(panel->hsli);
  91.     int sheight = WMGetSliderMaxValue(panel->vsli);
  92.  
  93.     x = WMGetSliderValue(panel->hsli);
  94.     y = WMGetSliderValue(panel->vsli);
  95.     
  96.     rx = x*(WMWidgetWidth(panel->porigF)-3)/swidth+2;
  97.     ry = y*(WMWidgetHeight(panel->porigF)-3)/sheight+2;
  98.     WMMoveWidget(panel->porigW, rx, ry);
  99.     
  100.     sprintf(buffer, "(%i,%i)", x, y);
  101.     WMSetLabelText(panel->porigvL, buffer);
  102. }
  103.  
  104.  
  105.  
  106. static void
  107. resistanceCallback(WMWidget *w, void *data)
  108. {
  109.     _Panel *panel = (_Panel*)data;
  110.     char buffer[64];
  111.     int i;
  112.  
  113.     i = WMGetSliderValue(panel->resS);
  114.  
  115.     if (i == 0)
  116.     WMSetLabelText(panel->resL, "OFF");
  117.     else {
  118.     sprintf(buffer, "%i", i);
  119.     WMSetLabelText(panel->resL, buffer);
  120.     }
  121. }
  122.  
  123.  
  124. static int
  125. getPlacement(char *str) 
  126. {
  127.     if (!str)
  128.     return 0;
  129.  
  130.     if (strcasecmp(str, "auto")==0)
  131.     return 0;
  132.     else if (strcasecmp(str, "random")==0)
  133.     return 1;
  134.     else if (strcasecmp(str, "manual")==0)
  135.     return 2;
  136.     else if (strcasecmp(str, "cascade")==0)
  137.     return 3;
  138.     else if (strcasecmp(str, "smart")==0)
  139.         return 4;
  140.     else
  141.     wwarning(_("bad option value %s in WindowPlacement. Using default value"),
  142.          str);
  143.     return 0;
  144. }
  145.  
  146.  
  147. static void
  148. showData(_Panel *panel)
  149. {
  150.     char *str;
  151.     proplist_t arr;
  152.     int x, y;
  153.  
  154.     str = GetStringForKey("WindowPlacement");
  155.  
  156.     WMSetPopUpButtonSelectedItem(panel->placP, getPlacement(str));
  157.  
  158.     arr = GetObjectForKey("WindowPlaceOrigin");
  159.  
  160.     x = 0; 
  161.     y = 0;
  162.     if (arr && (!PLIsArray(arr) || PLGetNumberOfElements(arr)!=2)) {
  163.     wwarning(_("invalid data in option WindowPlaceOrigin. Using default (0,0)"));
  164.     } else {
  165.     if (arr) {
  166.         x = atoi(PLGetString(PLGetArrayElement(arr, 0)));
  167.         y = atoi(PLGetString(PLGetArrayElement(arr, 1)));
  168.     }
  169.     }
  170.  
  171.     WMSetSliderValue(panel->hsli, x);
  172.     WMSetSliderValue(panel->vsli, y);
  173.  
  174.     sliderCallback(NULL, panel);
  175.  
  176.     x = GetIntegerForKey("EdgeResistance");
  177.     WMSetSliderValue(panel->resS, x);
  178.     resistanceCallback(NULL, panel);
  179.  
  180.     WMSetButtonSelected(panel->tranB, GetBoolForKey("OpenTransientOnOwnerWorkspace"));
  181.     
  182.     WMSetButtonSelected(panel->opaqB, GetBoolForKey("OpaqueMove"));
  183.     
  184.     WMSetButtonSelected(panel->miconB, GetBoolForKey("NoWindowOverIcons"));
  185.  
  186.     WMSetButtonSelected(panel->mdockB, GetBoolForKey("NoWindowOverDock"));
  187.  
  188.     if (GetBoolForKey("Attraction"))
  189.         WMPerformButtonClick(panel->resrB);
  190.     else 
  191.         WMPerformButtonClick(panel->resaB);
  192. }
  193.  
  194.  
  195. static void
  196. storeData(_Panel *panel)
  197. {
  198.     proplist_t arr;
  199.     char x[16], y[16];
  200.     
  201.     SetBoolForKey(WMGetButtonSelected(panel->miconB), "NoWindowOverIcons");
  202.     SetBoolForKey(WMGetButtonSelected(panel->mdockB), "NoWindowOverDock");
  203.     SetBoolForKey(WMGetButtonSelected(panel->opaqB), "OpaqueMove");
  204.     SetBoolForKey(WMGetButtonSelected(panel->tranB), "OpenTransientOnOwnerWorkspace");
  205.     SetStringForKey(placements[WMGetPopUpButtonSelectedItem(panel->placP)],
  206.             "WindowPlacement");
  207.     sprintf(x, "%i", WMGetSliderValue(panel->hsli));
  208.     sprintf(y, "%i", WMGetSliderValue(panel->vsli));
  209.     arr = PLMakeArrayFromElements(PLMakeString(x), PLMakeString(y), NULL);
  210.     SetObjectForKey(arr, "WindowPlaceOrigin");
  211.     SetIntegerForKey(WMGetSliderValue(panel->resS), "EdgeResistance");
  212.     SetBoolForKey(WMGetButtonSelected(panel->resrB), "Attraction");
  213.     PLRelease(arr);
  214. }
  215.  
  216.  
  217. static void
  218. createPanel(Panel *p)
  219. {
  220.     _Panel *panel = (Panel*)p;
  221.     WMScreen *scr = WMWidgetScreen(panel->win);
  222.     WMColor *color;
  223.     WMPixmap *pixmap;
  224.     int width, height;
  225.     int swidth, sheight;
  226.     char *path;
  227.     
  228.     panel->frame = WMCreateFrame(panel->win);
  229.     WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
  230.     WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
  231.     
  232.     /************** Window Placement ***************/
  233.     panel->placF = WMCreateFrame(panel->frame);
  234.     WMResizeWidget(panel->placF, 270, 110);
  235.     WMMoveWidget(panel->placF, 20, 10);
  236.     WMSetFrameTitle(panel->placF, _("Window Placement"));
  237.     WMSetBalloonTextForView(_("How to place windows when they are first put\n"
  238.                    "on screen."), WMWidgetView(panel->placF));
  239.  
  240.     panel->placP = WMCreatePopUpButton(panel->placF);
  241.     WMResizeWidget(panel->placP, 105, 20);
  242.     WMMoveWidget(panel->placP, 15, 20);
  243.     WMAddPopUpButtonItem(panel->placP, _("Automatic"));
  244.     WMAddPopUpButtonItem(panel->placP, _("Random"));
  245.     WMAddPopUpButtonItem(panel->placP, _("Manual"));
  246.     WMAddPopUpButtonItem(panel->placP, _("Cascade"));
  247.     WMAddPopUpButtonItem(panel->placP, _("Smart"));
  248.     
  249.     panel->porigL = WMCreateLabel(panel->placF);
  250.     WMResizeWidget(panel->porigL, 120, 32);
  251.     WMMoveWidget(panel->porigL, 5, 45);
  252.     WMSetLabelTextAlignment(panel->porigL, WACenter);
  253.     WMSetLabelText(panel->porigL, _("Placement Origin"));
  254.     
  255.     panel->porigvL = WMCreateLabel(panel->placF);
  256.     WMResizeWidget(panel->porigvL, 80, 20);
  257.     WMMoveWidget(panel->porigvL, 30, 75);
  258.     WMSetLabelTextAlignment(panel->porigvL, WACenter);    
  259.  
  260.     color = WMCreateRGBColor(scr, 0x5100, 0x5100, 0x7100, True);
  261.     panel->porigF = WMCreateFrame(panel->placF);
  262.     WMSetWidgetBackgroundColor(panel->porigF, color);
  263.     WMReleaseColor(color);
  264.     WMSetFrameRelief(panel->porigF, WRSunken);
  265.     
  266.     swidth = WidthOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
  267.     sheight = HeightOfScreen(DefaultScreenOfDisplay(WMScreenDisplay(scr)));
  268.     
  269.     if (sheight > swidth) {
  270.     height = 70;
  271.     width = 70*swidth/sheight;
  272.     if (width > 115)
  273.         width = 115;
  274.     height = 115*sheight/swidth;
  275.     } else {
  276.     width = 115;
  277.     height = 115*sheight/swidth;
  278.     if (height > 70)
  279.         height = 70;
  280.     width = 70*swidth/sheight;
  281.     }
  282.     WMResizeWidget(panel->porigF, width, height);
  283.     WMMoveWidget(panel->porigF, 130+(115-width)/2, 20+(70-height)/2);
  284.  
  285.     panel->porigW = WMCreateLabel(panel->porigF);
  286.     WMResizeWidget(panel->porigW, THUMB_SIZE, THUMB_SIZE);
  287.     WMMoveWidget(panel->porigW, 2, 2);
  288.     WMSetLabelRelief(panel->porigW, WRRaised);
  289.  
  290.     
  291.     panel->hsli = WMCreateSlider(panel->placF);
  292.     WMResizeWidget(panel->hsli, width, 12);
  293.     WMMoveWidget(panel->hsli, 130+(115-width)/2, 20+(70-height)/2+height+2);
  294.     WMSetSliderAction(panel->hsli, sliderCallback, panel);
  295.     WMSetSliderMinValue(panel->hsli, 0);
  296.     WMSetSliderMaxValue(panel->hsli, swidth);
  297.  
  298.     panel->vsli = WMCreateSlider(panel->placF);
  299.     WMResizeWidget(panel->vsli, 12, height);
  300.     WMMoveWidget(panel->vsli, 130+(115-width)/2+width+2, 20+(70-height)/2);
  301.     WMSetSliderAction(panel->vsli, sliderCallback, panel);
  302.     WMSetSliderMinValue(panel->vsli, 0);
  303.     WMSetSliderMaxValue(panel->vsli, sheight);
  304.  
  305.     WMMapSubwidgets(panel->porigF);
  306.  
  307.     WMMapSubwidgets(panel->placF);
  308.  
  309.     /************** Opaque Move ***************/
  310.     panel->opaqF = WMCreateFrame(panel->frame);
  311.     WMResizeWidget(panel->opaqF, 205, 110);
  312.     WMMoveWidget(panel->opaqF, 300, 10);
  313.     WMSetFrameTitle(panel->opaqF, _("Opaque Move"));
  314.     WMSetBalloonTextForView(_("Whether the window contents should be moved\n"
  315.                    "when dragging windows aroung or if only a\n"
  316.                    "frame should be displayed.\n"),
  317.                  WMWidgetView(panel->opaqF));
  318.  
  319.     panel->opaqB = WMCreateButton(panel->opaqF, WBTToggle);
  320.     WMResizeWidget(panel->opaqB, 64, 64);
  321.     WMMoveWidget(panel->opaqB, 70, 25);
  322.     WMSetButtonImagePosition(panel->opaqB, WIPImageOnly);
  323.  
  324.     path = LocateImage(NON_OPAQUE_MOVE_PIXMAP);
  325.     if (path) {
  326.     pixmap = WMCreatePixmapFromFile(scr, path);
  327.     if (pixmap) {
  328.         WMSetButtonImage(panel->opaqB, pixmap);
  329.         WMReleasePixmap(pixmap);
  330.     } else {
  331.         wwarning(_("could not load icon %s"), path);
  332.     }
  333.     free(path);
  334.     }
  335.     
  336.     path = LocateImage(OPAQUE_MOVE_PIXMAP);
  337.     if (path) {
  338.     pixmap = WMCreatePixmapFromFile(scr, path);
  339.     if (pixmap) {
  340.         WMSetButtonAltImage(panel->opaqB, pixmap);
  341.         WMReleasePixmap(pixmap);
  342.     } else {
  343.         wwarning(_("could not load icon %s"), path);
  344.     }
  345.     free(path);
  346.     }
  347.     WMMapSubwidgets(panel->opaqF);
  348.     
  349.     /**************** Account for Icon/Dock ***************/
  350.     panel->maxiF = WMCreateFrame(panel->frame);
  351.     WMResizeWidget(panel->maxiF, 205, 95);
  352.     WMMoveWidget(panel->maxiF, 300, 125);
  353.     WMSetFrameTitle(panel->maxiF, _("When maximizing..."));
  354.     
  355.     panel->miconB = WMCreateSwitchButton(panel->maxiF);
  356.     WMResizeWidget(panel->miconB, 185, 30);
  357.     WMMoveWidget(panel->miconB, 10, 18);
  358.     WMSetButtonText(panel->miconB, _("...do not cover icons"));
  359.  
  360.     panel->mdockB = WMCreateSwitchButton(panel->maxiF);
  361.     WMResizeWidget(panel->mdockB, 185, 30);
  362.     WMMoveWidget(panel->mdockB, 10, 53);
  363.  
  364.     WMSetButtonText(panel->mdockB, _("...do not cover dock"));
  365.  
  366.     WMMapSubwidgets(panel->maxiF);
  367.  
  368.     /**************** Edge Resistance  ****************/
  369.  
  370.     panel->resF = WMCreateFrame(panel->frame);
  371.     WMResizeWidget(panel->resF, 270, 45);
  372.     WMMoveWidget(panel->resF, 20, 125);
  373.     WMSetFrameTitle(panel->resF, _("Edge Resistance"));
  374.  
  375.     WMSetBalloonTextForView(_("Edge resistance will make windows `resist'\n"
  376.                    "being moved further for the defined threshold\n"
  377.                    "when moved against other windows or the edges\n"
  378.                    "of the screen."), WMWidgetView(panel->resF));
  379.  
  380.     panel->resS = WMCreateSlider(panel->resF);
  381.     WMResizeWidget(panel->resS, 80, 15);
  382.     WMMoveWidget(panel->resS, 10, 20);
  383.     WMSetSliderMinValue(panel->resS, 0);
  384.     WMSetSliderMaxValue(panel->resS, 80);
  385.     WMSetSliderAction(panel->resS, resistanceCallback, panel);
  386.  
  387.     panel->resL = WMCreateLabel(panel->resF);
  388.     WMResizeWidget(panel->resL, 30, 15);
  389.     WMMoveWidget(panel->resL, 95, 20);
  390.  
  391.     panel->resaB = WMCreateRadioButton(panel->resF);
  392.     WMMoveWidget(panel->resaB, 130, 12);
  393.     WMResizeWidget(panel->resaB, 70, 30);
  394.     WMSetButtonText(panel->resaB, _("Resist"));
  395.  
  396.     panel->resrB = WMCreateRadioButton(panel->resF);
  397.     WMMoveWidget(panel->resrB, 200, 12);
  398.     WMResizeWidget(panel->resrB, 65, 30);
  399.     WMSetButtonText(panel->resrB, _("Attract"));
  400.     WMGroupButtons(panel->resrB, panel->resaB);
  401.  
  402.  
  403.  
  404.     WMMapSubwidgets(panel->resF);
  405.  
  406.     /**************** Transients on Parent Workspace ****************/
  407.     
  408.     panel->tranF = WMCreateFrame(panel->frame);
  409.     WMResizeWidget(panel->tranF, 270, 40);
  410.     WMMoveWidget(panel->tranF, 20, 180);
  411.     
  412.     panel->tranB = WMCreateSwitchButton(panel->tranF);
  413.     WMMoveWidget(panel->tranB, 10, 5);
  414.     WMResizeWidget(panel->tranB, 250, 30);
  415.     WMSetButtonText(panel->tranB, _("Open dialogs in same workspace as their owners"));
  416.     
  417.     WMMapSubwidgets(panel->tranF);
  418.     
  419.     WMRealizeWidget(panel->frame);
  420.     WMMapSubwidgets(panel->frame);
  421.  
  422.     /* show the config data */
  423.     showData(panel);
  424. }
  425.  
  426.  
  427. static void
  428. undo(_Panel *panel)
  429. {
  430.     showData(panel);
  431. }
  432.  
  433.  
  434. Panel*
  435. InitWindowHandling(WMScreen *scr, WMWindow *win)
  436. {
  437.     _Panel *panel;
  438.  
  439.     panel = wmalloc(sizeof(_Panel));
  440.     memset(panel, 0, sizeof(_Panel));
  441.  
  442.     panel->sectionName = _("Window Handling Preferences");
  443.  
  444.     panel->description = _("Window handling options. Initial placement style\n"
  445.                "edge resistance, opaque move etc.");
  446.  
  447.     panel->win = win;
  448.     
  449.     panel->callbacks.createWidgets = createPanel;
  450.     panel->callbacks.updateDomain = storeData;
  451.     panel->callbacks.undoChanges = undo;
  452.         
  453.     AddSection(panel, ICON_FILE);
  454.     
  455.     return panel;
  456. }
  457.